﻿using System;
using Light.Framework.Castle;
using Light.Framework.Contract;
using Light.Utility;

namespace Light.Framework.Model
{

    /// <summary>
    /// 匿名用户（用于处理一些无需登录，匿名访问的任务）
    /// </summary>
    public class GuestUser : User, IDisposable
    {
        const string session_name = "session_light_framework_castle_appuser";

        public GuestUser()
        {
            if (ServerApplication.User != null && ServerApplication.User.Organization != null)
                WebHelper.SetSession(session_name, ServerApplication.User);

            ServerApplication.User = new Light.Framework.Model.User
            {
                Name = "匿名用户",
                IsApprole = true,
                Organization = null
            };
        }

        public void Dispose()
        {
            ServerApplication.User = WebHelper.GetSession<IUser>(session_name);
        }

    }
}
